package util;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ResourceBundle;

import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import modelUtil.Util;
import paginas.PaginaAspectoBoton;
import AccionBoton.AccionCambioColorRaton;
import AccionBoton.AccionCerrar;
import AccionBoton.AccionCerrarCruz;
import AccionBoton.AccionFocoCreditos;

public class PopUpSeleccionColorRaton extends JDialog implements ChangeListener{


	private PaginaAspectoBoton _frame;
	private JColorChooser _selector;
	private String _tipo;
	private String ColorViejo;
	private Color newColor;
	
	public PopUpSeleccionColorRaton(PaginaAspectoBoton frame, String tipo){
		
		_frame = frame;
		_tipo = tipo;
		JPanel panel = new JPanel();
		GridBagLayout grid = new GridBagLayout();
		GridBagConstraints cons = new GridBagConstraints();
		FlowLayout flow = new FlowLayout();
		panel.setLayout(flow);
		cons.fill = GridBagConstraints.BOTH;
		cons.gridheight = 1;
		cons.gridwidth = 1;
		cons.gridx = 0;
		cons.gridy = 0;
		if(_tipo.equals("paso")){
				_selector = new JColorChooser(_frame.get_boton().getColorMouseOver());
		}else{
			if(_tipo.equals("click")){
				
				_selector = new JColorChooser(_frame.get_boton().getColorPresionado());

			}
			
		}
		//_selector.setPreferredSize(new Dimension(600,460));
		BotonPersonalizado aceptar = Util.BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_aceptar"), "lib//Aceptar.png");
		BotonPersonalizado cancelar = Util.BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_cancelar"), "lib//cancelar.png");
		
		
		aceptar.getLabelImagen().setHorizontalAlignment(SwingConstants.LEFT);
		aceptar.getLabelTexto().setHorizontalAlignment(SwingConstants.RIGHT);
		cancelar.getLabelImagen().setHorizontalAlignment(SwingConstants.LEFT);
		cancelar.getLabelTexto().setHorizontalAlignment(SwingConstants.RIGHT);
		aceptar.setBackground(Color.lightGray);
		cancelar.setBackground(Color.lightGray);
		aceptar.setMnemonic('a');
		cancelar.setMnemonic('c');
		aceptar.getLabelImagen().setDisplayedMnemonic('a');
		cancelar.getLabelImagen().setDisplayedMnemonic('c');
		
		aceptar.setPreferredSize(new Dimension(150,40));
		cancelar.setPreferredSize(new Dimension(150,40));

		aceptar.addFocusListener(new AccionFocoCreditos(aceptar));
		cancelar.addFocusListener(new AccionFocoCreditos(cancelar));
		
		aceptar.addActionListener(new AccionCambioColorRaton(this));
		cancelar.addActionListener(new AccionCerrar(this, _frame));
		
		panel.setPreferredSize(new Dimension(320,50));
		flow.addLayoutComponent("aceptar", aceptar);
		panel.add(aceptar);
		flow.addLayoutComponent("cancelar", cancelar);
		panel.add(cancelar);
		setLayout(grid);
		grid.addLayoutComponent(_selector, cons);
		this.add(_selector);
		cons.gridy = 1;
		grid.addLayoutComponent(panel, cons);
		this.add(panel);
		 _selector.getSelectionModel().addChangeListener(this);
		 addComponentListener(new AccionCerrarCruz(this,_frame));
		setBounds(0, 0, 600, 500);
		setAlwaysOnTop(true);
		setLocationRelativeTo(null);
		setModal(true);
		this.pack();
		this.repaint();
		setVisible(true);
		
		
	}
	

	public void stateChanged(ChangeEvent e){
		
        newColor = _selector.getColor();
    	ColorViejo = new Integer(newColor.getRGB()).toString();
		
	}


	public PaginaAspectoBoton get_frame() {
		return _frame;
	}


	public void set_frame(PaginaAspectoBoton frame) {
		_frame = frame;
	}


	public String get_tipo() {
		return _tipo;
	}


	public void set_tipo(String tipo) {
		_tipo = tipo;
	}



	public String getColorViejo() {
		return ColorViejo;
	}


	public void setColorViejo(String colorViejo) {
		ColorViejo = colorViejo;
	}


	public Color getNewColor() {
		return newColor;
	}


	public void setNewColor(Color newColor) {
		this.newColor = newColor;
	}
	
	
	
}
